////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                            //
//                                                         WNProject                                                          //
//                                                                                                                            //
//            This file is distributed under the BSD 2-Clause open source license. See License.txt for details.               //
//                                                                                                                            //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef __WN_EXECUTE_ONCE_H__
#define __WN_EXECUTE_ONCE_H__

#include "WNCore/inc/WNBase.h"

typedef WN_VOID (*WN_EXECUTE_ONCE_FUNCTION_T)();

#ifdef _WN_LINUX
    #include <pthread.h>

    typedef pthread_once_t WN_EXECUTE_ONCE_T;

    #define WN_EXECUTE_ONCE_INIT PTHREAD_ONCE_INIT

    #define WN_EXECUTE_ONCE_FUNCTION(_function) extern "C" WN_VOID __WN_CDECL_BEGIN _function() __WN_CDECL_END
#else
    typedef WN_ATOM_T WN_EXECUTE_ONCE_T;

    #define WN_EXECUTE_ONCE_INIT 0

    #define WN_EXECUTE_ONCE_FUNCTION(_function) static WN_VOID _function()
#endif

__WN_INLINE WN_VOID WNExecuteOnce(WN_EXECUTE_ONCE_T* _control, WN_EXECUTE_ONCE_FUNCTION_T _function);

#include "WNConcurrency/inc/WNExecuteOnce.inl"

#endif // __WN_EXECUTE_ONCE_H__